package com.cardetective.shopcar.page.activity

import com.alibaba.fastjson.JSON
import com.android.basemvvm.BaseViewModel
import com.pinyuana.dragongame.network.model.GenerateAiAgentCallModel
import com.pinyuana.dragongame.utils.HttpClientUtil

class SplashViewModel: BaseViewModel() {


    /**
     * 验证滑块结果
     */
    fun getGenerateAiAgentCall() {
        launch {
            val url = "https://aidemo.qa.meixinyun.net/api/v2/aiagent/generateAIAgentCall"
            val jsonParams = "{\"user_id\":\"mock_user_id\",\"workflow_type\":\"VoiceChat\",\"expire\":86400,\"template_config\":\"{\\\"VoiceChat\\\":{\\\"UserOnlineTimeout\\\":60,\\\"UserOfflineTimeout\\\":5,\\\"AsrMaxSilence\\\":400,\\\"EnableVoiceInterrupt\\\":true,\\\"EnableIntelligentSegment\\\":true,\\\"UseVoiceprint\\\":true,\\\"VoiceprintId\\\":\\\"mock_user_id\\\",\\\"MaxIdleTime\\\":600}}\"}"
            val result = HttpClientUtil.postJson(url,null,jsonParams)

            if (result.isSuccess) {
                val data = result.getOrNull()
                // 处理成功的数据
                data?.let {
                    val parseObject = JSON.parseObject(data, GenerateAiAgentCallModel::class.java)
                    if (parseObject.code == 200){
                        mBVOnExceptionListener?.onListener(200,JSON.toJSONString(parseObject))
                    }else{
                        mBVOnExceptionListener?.onListener(-1,JSON.toJSONString(parseObject))
                    }
                }
            } else {
                val exception = result.exceptionOrNull()
                mBVOnExceptionListener?.onListener(-1,exception.toString())
                // 处理失败的情况
                exception?.printStackTrace()
            }
        }
    }
}